package com.awenhui.demo.core.validation.validator;


import com.awenhui.demo.core.validation.annotation.PhoneNo;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 手机号码验证器
 *
 * @author yuxf
 * @version 1.0
 * @date 2020/5/11 15:50
 */
public class PhoneNoValidator implements ConstraintValidator<PhoneNo, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isBlank(value)) {
            return true;
        }
        String regexp = "^1[0-9]{10}$";
        return value.matches(regexp);
    }
}
